<template>
  <div class="model-form">
    <el-page-header @back="goBack" content="更新会员">
    </el-page-header>
    <div class="model-content">
      <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
        <el-row :gutter="10">
          <el-col :span="22">
            <el-form-item label="个人头像" size="mini" prop="avatar">
              <avatar v-model="form.avatar"></avatar>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" size="mini" prop="name">
              <el-input v-model="form.name" name="name">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="电话" size="mini" prop="phone">
              <el-input v-model="form.phone" name="phone">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="会员等级" size="billboardItem" prop="sex">
              <el-select style="width:100%;"   clearable filterable   v-model="form.billboardItem"
                         placeholder="请选择">
                <el-option
                    v-for="item in billBoardItems"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="认证状态" size="mini" prop="auditState">
              <el-select style="width:100%;"   clearable filterable   v-model="form.auditState"
                         placeholder="请选择">
                <el-option label="未认证" value="init"></el-option>
                <el-option label="已认证" value="audit"></el-option>
                <el-option label="已签约" value="sign"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" size="mini" prop="sex">
              <nb-select catalog="sex" v-model="form.sex"></nb-select>
            </el-form-item>

          </el-col>
          <el-col :span="11">
            <el-form-item label="年龄" size="mini" prop="age">
              <el-input-number v-model="form.age" name="age" type="textarea" :min="0" :max="100"></el-input-number>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号" size="mini" prop="cardNo">
              <el-input v-model="form.cardNo" name="cardNo">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="11">
            <el-form-item label="现住址" size="mini" prop="address">
              <el-input v-model="form.address" name="address">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业院校" size="mini" prop="school">
              <el-input v-model="form.school" name="school">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="11">
            <el-form-item label="身高" size="mini" prop="height">
              <el-input v-model="form.height" name="height">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="体重" size="mini" prop="weight">
              <el-input v-model="form.weight" name="weight">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="11">
            <el-form-item label="三围" size="mini" prop="threeLatitude">
              <el-input v-model="form.threeLatitude" name="threeLatitude">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="个人介绍" size="mini" prop="note">
              <el-input v-model="form.note" name="note" type="textarea">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="照片">
              <img v-if="form.lifePhoto!=null" :src="form.lifePhoto" class="logoImage" />
              <img v-if="form.modelPhoto!=null" :src="form.modelPhoto" class="logoImage" />
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item>
              <el-button @click="goBack">取消</el-button>
              <el-button type="primary" @click="updateData">确定</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import nbSelect from "@/components/nbSelect.vue";
import avatar from "@/components/avatar.vue";

import common from "@/mixins/common.js";

export default {
  name: "model_update",
  mixins: [common],
  components: {
    nbSelect, avatar
  },
  data() {
    return {
      form: {
        name: '',
        avatar: '',
        phone: '',
        sex: '',
        age: '',
        cardNo: '',
        address: '',
        school: '',
        height: '',
        weight: '',
        threeLatitude: '',
        recommender: '',
        fee: '',
        billboardItem:"",
        auditState:""
      },
      billBoardItems:[],
      rules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ],
        avatar: [
          {required: true, message: '请输入照片', trigger: 'blur'}
        ],
        phone: [
          {required: true, message: '请输入电话', trigger: 'blur'}
        ],
      }
    }
  },
  async mounted() {
    let id = this.$route.query.id;
    let data = {};
    data.id = id;
    let res = await this.$http.form("/tenantRest/staff/view.htm", data);
    if (res.code === 0) {
      this.form = res;
    }
   await this.loadBillBoardItems();
  },
  methods: {
    async loadBillBoardItems(){
      let param={};
      param.size=100;
      param.key="level";
      param.sortField="sortNum";
      param.sortMethod="asc";
      let res = await this.$http.form("/tenantRest/billboarditem/list.htm", param);
      if (res.code === 0) {
        this.billBoardItems = res.list;
      }
    },
    async updateData() {
      let res = await this.$refs["ruleForm"].validate();
      if (!res) {
        return;
      }
      await this.updateDataPost();
    },
    async updateDataPost() {
      let res = await this.$http.form("/tenantRest/staff/update.htm", this.form);
      if (res.code !== 0) {
        this.$message.error(res.msg);
        return
      }
      this.$message({
        message: '更新数据成功',
        type: 'success'
      });
      this.$router.go(-1);
    },

  }
}


</script>

<style scoped>
.logoImage{
  width: 100px;
  height: auto;
  margin-right: 15px;
}
</style>
